package com.bw.common.view

import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import com.bw.common.viewmodel.BaseViewModel
import java.lang.reflect.ParameterizedType

abstract class BaseMVIFragment<VDB:ViewDataBinding,VM: BaseViewModel<*>>: BaseViewFragment<VDB>() {


    private val type by lazy { (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments }

    //直接通过泛型拿到对应的ViewModel的class,来进行实例化
    protected val vm: VM by lazy {
        val clazz = type[1] as Class<VM>
        ViewModelProvider(this)[clazz]
    }




}